package org.ch00.test12;


/*
 *
 *@author XCH
 *@date 2025 - 03 - 12 - 11:46
 *
 */
public class BankAccount {
    private int balance = 5000;
    private final Object lock = new Object();

    public void withdraw(String name, int amount) {
        synchronized (lock) {
            System.out.println("开始取款....");
            System.out.println("剩余余额：" + balance);
            if (balance >= amount) {
                System.out.println(name + " 正在取款: " + amount);
                balance -= amount;
                System.out.println(name + " 取款成功，剩余余额: " + balance);
            } else {
                System.out.println(name + " 正在取款: " + amount);
                System.out.println(name + " 取款失败，余额不足!");
            }
        }
    }
}

